<form action="javascript:void(0)" method="POST" id="purapp-list">
	<div id="group">
		<div id="search">
			<input type="text" name="search-text" /><a href="javascript:void(0)" target="_self">搜索</a>
		</div>
		<?php if(isset($page['display'])) { ?>
		<div id="page">
			<div id="process"><?php echo $page['total_rows'] ?> 中的 <?php echo $page['start'] . '-' . $page['end'] ?></div>
			<?php echo $page['display']; ?>
		</div>
		<?php } ?>
	</div>
	<div id="list">
		<?php foreach ($purapps as $pa) { ?>
		<div class="purapp-list each">
			<input type="hidden" value="<?php echo $pa->pur_app_id; ?>" />
			<div class="number"><?php echo $pa->pur_app_number; ?></div>
			<div class="status"><?php echo $purapp_status[$pa->pur_app_status]; ?></div>
			<div class="person"><?php echo $pa->pur_app_person; ?></div>
			<div class="desc"><?php echo $pa->pur_app_goods; ?></div>
			<div class="create"><?php echo $pa->create_date; ?></div>
		</div>
		<?php } ?>
	</div>
</form>
<script>
$(function(){
	//显示描述
	purchase.app_list.desc();
	//格式化时间
	$('.each .create').each(function(){
		$(this).text(tool.getLocalTime($(this).text()));
	});
	//显示采购单详情
	$('.purapp-list').click(function(){
		$obj = $(this);
		purchase.detail($(this).find('input').val(), function(html){
			$o = $(html).find('.ajax-number');
			data = '{"sub_goods_ids":[';
			$o.each(function(){
				data += '"' + $(this).text() + '",';
			});
			data = data.slice(0,-1) + ']}';
			data = tool.toJson(data);
			url = site.url + 'goods/ajax_get_some_sub_goods/';
			$('#purapp-list-detail').remove();
			$('.purapp-list').removeAttr('style');
			style.loading('start');
			$.post(url, data, function(result){
				json = tool.toJson(tool.toJson(result).d);
				arr = [];
				$.each(json, function(k, v){
					arr[k] = v;
				});
				$obj.after($(html)).css('border-top', '1px solid #ddd');
				//console.log(arr);
				//Start to replace the value where we get by using AJAX
				$('.ajax-number').each(function(){
					key = $(this).text();
					$(this).text(arr[key].number);
					$(this).siblings('.ajax-pro').text(arr[key].attribute).siblings('.ajax-scode').text(arr[key].search_code);
				});
				style.loading('end');
			});
		})
	});
})
</script>